package cn.qihua.action;

import java.sql.Timestamp;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import cn.qihua.model.LogOrder;
import cn.qihua.model.SysUser;
import cn.qihua.service.ILogService;
import cn.qihua.service.IUserService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author 米修
 * 
 */

public class LogOrderAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2742912262570154969L;
	private ILogService logService;
	public String message;
	private boolean success = false;
	private int id;

	private LogOrder LogOrder = new LogOrder();

	public String addLog() {
		Subject subject = SecurityUtils.getSubject();
		Integer uid = (Integer) subject.getSession().getAttribute("UID");
		LogOrder.setInDate(new Timestamp(System.currentTimeMillis()));
		LogOrder.setIsNew(true);
		LogOrder.setOrderId(id);
		LogOrder.setUserId(uid);
		if (logService.add(LogOrder)) {
			this.setSuccess(true);
			this.setMessage("已添加跟进信息！");
			return SUCCESS;
		}
		this.setSuccess(false);
		this.setMessage("跟进失败！");
		return ERROR;
	}

	public String editLog() {
		return null;
	}

	public String delLog() {
		if (logService.delLogOrder(id)) {
			this.setSuccess(true);
			this.setMessage("删除成功！");
			return SUCCESS;
		} else {
			this.setSuccess(false);
			this.setMessage("删除失败！");
			return ERROR;
		}
	}

	public String search() {
		return SUCCESS;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public LogOrder getLogOrder() {
		return LogOrder;
	}

	public void setLogOrder(LogOrder LogOrder) {
		this.LogOrder = LogOrder;
	}
	
	public void setLogService(ILogService logService) {
		this.logService = logService;
	}

}
